package org.shagin.jfin.data.model;

import java.util.ArrayList;
import java.util.Currency;
import java.util.List;

import org.shagin.jfin.data.Money;
import org.shagin.jfin.data.util.MoneyUtil;

/**
 * The Class CostCenter.
 */
public class CostCenter extends AbstractBudgetItem {

    private List<Account> accounts = new ArrayList<Account>();

    /**
     * Instantiates a new cost center.
     * 
     * @param costCenterId the cost center id
     */
    public CostCenter(String costCenterId, IBudget budget) {
        super(costCenterId);
        this.budget = budget;
    }

    /**
     * Gets the accounts.
     * 
     * @return the accounts
     */
    public List<Account> getAccounts() {
        return accounts;
    }

    /**
     * Gets the amount.
     * 
     * @param currency the currency
     * @return the amount
     */
    public Money getAmount(Currency currency) {
        Money result = MoneyUtil.zero(currency);
        for (Account account : accounts) {
            result = MoneyUtil.add(result, account.getAmount(), currency);
        }
        return result;
    }
}
